package com.chendx.store.goods.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chendx.model.common.dtos.ResponseResult;
import com.chendx.model.goods.dto.SpuDto;
import com.chendx.model.goods.dto.SpuInfoDto;
import com.chendx.model.goods.pojo.Spu;
import com.chendx.store.api.goods.SpuControllerApi;
import com.chendx.store.goods.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by chendx on 2022/4/18.
 */

@RestController
@RequestMapping("/api/spu")
public class SpuController implements SpuControllerApi{

    @Autowired
    private SpuService spuService;

    @Override
    @GetMapping("/one/{id}")
    public Spu findById(@PathVariable("id") Long id) {
        return spuService.getById(id);
    }



    @Override
    @GetMapping("/list")
    public List<Spu> spuList(){
        return spuService.list(Wrappers.<Spu>lambdaQuery().eq(Spu::getIsDelete,"0").eq(Spu::getIsMarketable,"0"));
    }

    @Override
    @PostMapping("/infos")
    public ResponseResult spuInfos(@RequestBody SpuDto dto) {
        return spuService.spuInfos(dto);
    }

    @Override
    @GetMapping("/info")
    public ResponseResult info(String id) {
        return spuService.spuInfo(id);
    }

    @Override
    @PostMapping("/add")
    public ResponseResult save(@RequestBody SpuInfoDto dto) {
        return spuService.add(dto);
    }
}
